package br.inf.mensageiro.converter;

import java.net.DatagramPacket;
import java.net.InetAddress;

import br.inf.mensageiro.pojo.Status;
import br.inf.mensageiro.pojo.Usuario;

public class UsuarioConverter {

	public static Usuario converter(DatagramPacket pkg){
		InetAddress address = pkg.getAddress();
		String ipRemote = address.getHostAddress();
		String received = new String(pkg.getData(), 0, pkg.getLength());
		String[] receivedSplit = received.split("\\|");
		Usuario usuario = new Usuario();
		usuario.setIpRemote(ipRemote);
		usuario.setStatus(Status.valueOf(receivedSplit[0]));
		usuario.setUserName(receivedSplit[1]);
		usuario.setAlias(receivedSplit[2]);
		
		return usuario;
	}
	
}
